import { _decorator, Component, Label, Node } from 'cc';
import { GAME_POP, GlobalData, SOUND_TYPE } from '../../Data/GlobalData';
import { BaseComponent } from '../../Manager/UIManager/BaseComponent';
import { PopSet } from '../../Pop/PopSet/PopSet';
const { ccclass, property } = _decorator;

@ccclass('BluttonLoad')
export class BluttonLoad extends BaseComponent {

    //播放按钮
    @property(Node)
    private PlayBtn: Node = null;

    //关卡文字
    @property(Label)
    public LevelLabel: Label = null;

    protected OnShow(): void {
        this.PlayBtn.active = false;
    }

    /**
     * 暂停点击
     */
    private PauseClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        this.PlayBtn.active = !this.PlayBtn.active;

        if (this.PlayBtn.active) {
            console.log("暂停")
            GlobalData.GameOver = true;
            app.popManager.ShowPop(GAME_POP.PopSet);
            app.popManager.CurrentPop.getComponent(PopSet).GoLoginBtn.active = true;
            app.popManager.CurrentPop.getComponent(PopSet).Cb = this.GoGame.bind(this);
        } else {
            console.log("继续")
        }
    }

    /**
     * 继续游戏
     */
    private GoGame() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        this.PlayBtn.active = false;
        GlobalData.GameOver = false;
    }

    /**
     * 道具点击
     */
    private PropClick(_e: any, _cus: string) {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        switch (Number(_cus)) {
            case 0://道具0
                console.log("道具0");

                GlobalData.GameOver = true;
                app.adManager.ShowVideo(0, (_isend: boolean) => {
                    GlobalData.GameOver = false;
                    if (_isend) {
                        GlobalData.ButtleSpeed = 20;
                        app.topManager.ShowPrompt("子弹加速成功");
                    } else {
                        app.topManager.ShowPrompt("使用道具失败");
                    }
                })

                break;
            case 1://道具1
                GlobalData.GameOver = true;
                app.adManager.ShowVideo(0, (_isend: boolean) => {
                    GlobalData.GameOver = false;
                    if (_isend) {
                        GlobalData.BodyAddSpeed = -50;
                        app.topManager.ShowPrompt("敌人减速成功");
                    } else {
                        app.topManager.ShowPrompt("使用道具失败");
                    }
                })
                break;
            case 2://道具2
                console.log("道具2");

                GlobalData.GameOver = true;
                app.adManager.ShowVideo(0, (_isend: boolean) => {
                    GlobalData.GameOver = false;
                    if (_isend) {
                        GlobalData.IsHit = false;
                        app.topManager.ShowPrompt("点击喵咪无视碰撞");
                    } else {
                        app.topManager.ShowPrompt("使用道具失败");
                    }
                })

                break;
        }
    }

    /**
     * 使用道具
     */
    public UseProp() {

    }

}


